package com.scm.integration;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;

import scm.classifica.jaxb.CLSBean;
import scm.classifica.jaxb.Team;

import scm.live.jaxb.CMPBean;
import scm.live.jaxb.LIVE;
import scm.live.jaxb.MATCHSType;
import scm.live.jaxb.MATCHTBean;
import scm.quote.jaxb.Match;
import scm.quote.jaxb.SCMBean;

import com.scm.error.SCPException;
import com.scm.ingestion.Ingestion;
import com.scm.ingestion.IngestionImpl;
import com.scm.parser.StatisticLive;
import com.scm.parser.TEXTParserLive;
import com.scm.property.IPropertyIDCamp;
import com.scm.property.PropertyConfig;
import com.scm.property.IPropertyConfig;
import com.scm.property.PropertyIDCamp;

public class ScmMain {
	
	private static Logger log = Logger.getLogger(ScmMain.class);
	
	public static void main(String[] args) throws IOException, InterruptedException {
		
		Ingestion ingestion = new IngestionImpl();
		
		IPropertyConfig prop = new PropertyConfig();
		IPropertyIDCamp legenda = new PropertyIDCamp();
		InterfaceSCM intf = new SCMImpl();
		List<String> listCampIngestion = prop.getListaCmpIngestion();
		List<String> idListCampionati = intf.getIdCampionati();	

		
		ingestion.startDeleteLive();
		ingestion.startDeleteCmpLive();
				
				for(CMPBean compList : intf.getCmpLive()){
					ingestion.startIngestionCompetation(compList);
					for(MATCHTBean  match : intf.getLiveScore(compList)){
						log.info(match.getCMP()+" -> "+match.getCMP()+" - "+match.getSTATUS()+" -  "+match.getSQ1()+"-"+match.getSQ2()+" = "+match.getSCORE());
						ingestion.startIngestionLive(match);
					}
				}

	
		
		//ingestion.startDeleteClass();
		//ingestion.startDeleteQuote();
		//ingestion.startDeleteIdCmp();
		
		for(String ID : listCampIngestion){
			CLSBean resultClss = intf.getClassifica(legenda.getStringName(ID));
			if(resultClss != null)
				for(Team team : resultClss.getTeam()){
				//	ingestion.startIngestionClass(team);
				//	log.info(team);
				}
		}//END INGESTION
		
	
		SCMBean scm = intf.getQuote();
		if(scm != null)
			for(Match match : scm.getMatch()){
				if(listCampIngestion.contains(match.getTipoAvv())){
					//ingestion.startIngestionQuote(match);
					//log.debug(match.getTipoAvv()+" - "+match.getSquadraGuest()+" - "+match.getRisultatoFinale());
				}
		}
	
	
		for(String id : idListCampionati){
			if(listCampIngestion.contains(id)){
		    	//ingestion.startIngestionIDCamp(id,listCampIngestion.indexOf(id));
		    	//log.debug(id+"->"+legenda.getStringName(id));
			}
		}
	}
	
}
	

